<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>商场物品兑换订单</title>
	<%@ include file="/view/common/tags.jsp"%>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta content="width=device-width, initial-scale=1" name="viewport" />
    <meta content="" name="description" />
    <meta content="" name="author" />
<body>
<section class="content">
 	<div class="row"> 
    	<div class="col-md-12">
	     	<div class="box">
	            <div class="box-body">
	               <div class="panel panel-default">
	                    <div class="panel-body" style="padding-bottom:5px;">
	                        <form class="form-horizontal" action="/pubgExchangeOrder/list" method="post" id="pubgExchangeOrderForm">
	                            <div class="searchMenu">
									<div>
										<label>俱乐部：</label>
										<select cssClass="form-control select" name="wm[CLUB_ID]">
											<option value="">请选择</option>
											<c:if test="${clubList != null && fn:length(clubList) > 0}">
												<c:forEach items="${clubList}" var="pubgClub">
													<option value="${pubgClub.rowId}">${pubgClub.clubName}</option>
												</c:forEach>
											</c:if>
										</select>
									</div>
									<div>
										<label>状态：</label>
										<sk:select cssClass="form-control select" name="wm[CONVERSION_STATE]" value="${page.wm.CONVERSION_STATE}" >
											<option value="">请选择</option>
											<option value="10">待处理</option>
											<option value="20">处理完成</option>
											<option value="30">已撤销</option>
										</sk:select>
									</div>
	                                <div  class="mal10">
	                                    <button type="button"  class="btn btn-primary btn-sm"  onclick="findData()"><span class='glyphicon glyphicon-search'></span>查&nbsp;询</button>
	                                </div>
	                            </div>
	                        </form>
	                    </div>
	                </div>
	                <table class="table-scrollable table table-hover  table-bordered" id="pubgExchangeOrderTable" data-striped=true>
	                    <thead>
	                        <tr>
	                            <th data-field="index" data-align="center" data-formatter="indexFormatter" data-sortable="false">序号</th>
	                            <th data-field="orderNo" data-align="center">相关单号</th>
	                            <th data-field="userAccount" data-align="center">用户帐号</th>
								<th data-field="teamName" data-align="center">所属战队</th>
								<th data-field="clubName" data-align="center">所属俱乐部</th>
								<th data-field="goodsName" data-align="center">兑换物品</th>
								<th data-field="applyTime" data-align="center" data-formatter="timeFormatter_point" >兑换时间</th>
								<th data-field="conversionState" data-align="center" data-formatter="conversionStateFormatter" data-sortable="true">状态</th>
	                            <th data-field="optButton" data-align="center" data-sortable="false" data-formatter="buttonFormatter">操作</th>
	                        </tr>
	                    </thead>
	                </table>
	            </div>
	        </div>
		</div>
	</div>
	<input type="hidden" id="msgg"  value="${msg}">
	<input type="hidden" id="code"  value="${code}">
</section>
   <%@ include file="/view/common/footer.jsp"%>
</body>
<script>
    var msgg = $("#msgg").val();
    var code = $("#code").val();
    $(function(){
        if( code== 1) {
            layer.msg(msgg);
        }
    })
    function conversionStateFormatter(value, row) {
        var html = "";
        if (row.conversionState == "10") {
            html = "<span class='text-warning'>待处理 </span>&nbsp;&nbsp;&nbsp;&nbsp;";
            return html;
        } else if (row.conversionState == "20") {
            html = "<span class='text-success'>处理完成 </span>&nbsp;&nbsp;&nbsp;&nbsp;";
            return html;
        } else if (row.conversionState == "30") {
            html = "<span class='text-danger'>已撤销 </span>&nbsp;&nbsp;&nbsp;&nbsp;";
            return html;
        }
    }

    //操作按钮
    function buttonFormatter(value, row,index) {
        if (row.conversionState == "10" && row.pubgUser.userRole == "30") {
            var e = "<button id='btn_edit' type='button' onclick='updateOrderConversionState("+row.rowId+",20);'  class='btn btn-default btn-sm'><span class='glyphicon glyphicon-pencil'></span>处理完成</button>";
            var f = "<button id='btn_edit' type='button' onclick='updateOrderConversionState("+row.rowId+",30);'  class='btn btn-default btn-sm'><span class='glyphicon glyphicon-pencil'></span>撤销兑换</button>";
            return e + "&nbsp;" + f;
		}
    }

    //处理完成/撤销兑换
    function updateOrderConversionState(rowId, conversionState){
        var title = "";
        var descStr = "";
        if (conversionState == 20) {
            title = "<span style = 'color:red'>确认已完成线下打款?</span>";
            descStr = "处理完成操作";
		} else if (conversionState == 30) {
            title = "<span style = 'color:red'>确认作废此兑换订单?</span>";
            descStr = "撤销兑换操作";
		}
        layer.confirm(title, {
                btn: ['确认', '取消']
            },
            function(){
                if (rowId == null || rowId == "") {
                    layer.msg("id不能为空!");
                    return;
                }
                $.post(JSSYSMANAGERV1 + "/pubgExchangeOrder/updateOrderConversionState?rowId="+rowId+"&conversionState="+conversionState,null,function(json){
                    if (json == 1) {
                        layer.msg(descStr+"成功", {icon: 1});
                        findData();
                    } else if(json == "-2"){
                        window.location.href= JSCTX;
                    } else {
                        layer.msg(descStr+"失败", {icon: 5});
                    }
                });
            },
            function(){
                return;
            });
    }

    $(function(){
        $("#pubgExchangeOrderTable").bootstrapTable({
            url: JSSYSMANAGERV1 + "/pubgExchangeOrder/listPubgExchangeOrder.json",
            method:"get",
            pagination:true,
            sidePagination:"server",
            queryParams: function(params) {
                return $.extend({}, params, parseJson(decodeURIComponent($("#pubgExchangeOrderForm").serialize())));
            }
        });
    })
    function findData(){
        $("#pubgExchangeOrderTable").bootstrapTable("refresh",{} );
    }
</script>
</html>